﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SubscriberPattern {
	public class Component : ISubscribe, IPublish {
		private string subsribeName;
		public Component(string subName) {
			this.subsribeName = subName;
		}

		private SubscribeHandle subscribeEvent;
		event SubscribeHandle ISubscribe.SubscribeEvent {
			add { subscribeEvent += value; }
			remove { subscribeEvent -= value; }
		}

		public PublishHandle publishEvent;
		event PublishHandle IPublish.PublishEvent {
			add { publishEvent += value; }
			remove { publishEvent += value; }
		}

		public void Notify(string str) {
			if (subscribeEvent != null) {
				subscribeEvent.Invoke("Message from " + subsribeName + ": " + str);
			}
		}
	}
}